package GUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class QuPanel extends JPanel implements ActionListener {
    private ImageIcon imageIcon = Utilimg.getIcon("/img/buttonOff.jpg");
    private ImageIcon imageIcon1 = Utilimg.getIcon("/img/buttonSure.jpg");
    private JButton qujButton;
    private JButton qujButton1;
    private Text2 frame;
    private JTextField jTextField;

    public QuPanel(Text2 frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        JLabel jLabel = new JLabel("取款:");
        jLabel.setBounds(200, 150, 100, 50);
        jLabel.setFont(new Font("宋体", Font.BOLD, 30));
        this.add(jLabel);

        jTextField = new JTextField();
        jTextField.setBounds(300, 160, 200, 30);
        this.add(jTextField);

        qujButton = new JButton(imageIcon);
        qujButton.setBounds(690, 250, 100, 50);
        this.add(qujButton);
        qujButton.addActionListener(this);

        qujButton1 = new JButton(imageIcon1);
        qujButton1.setBounds(0, 250, 100, 50);
        this.add(qujButton1);
        qujButton1.addActionListener(this);
    }

    public void qu() {
        double a=Double.valueOf(jTextField.getText());
        double b=frame.getLoginUser().getBalance();
        if(a>b){
            JOptionPane.showMessageDialog(this,"余额不足，请重新输入");
        }else {
            frame.getChaPanel().Set(b-a);
            JOptionPane.showMessageDialog(this,"取款成功");
        }


    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == qujButton) {
            frame.switchPanel("menu");
        }else if(e.getSource()==qujButton1){
            frame.getQuPanel().qu();

        }
    }
}
